/**
 * Created by root on 5/12/17.
 */
var bookServices = angular.module('books.services', [ 'ngResource' ]);
bookServices.factory('BookTypeTree', function($http,$rootScope, $q) {

    function Tree() {
        this.load = function ($scope) {
            var promises = [];
            promises.push($http.get('/api/book/classification').success(function (data) {
                var trees = [];
                _.each(data.data,function(item){
                    var t = {id:item.id,text:item.classificationName,parent:'root'};
                    trees.push(t);
                })

                var root = {};
                root.id="root";
                root.text="图书分类";
                root.parent="#";
                root.type="Root";
                root.state={"opened":false};
                $scope.localBookTypeTree = trees;
                $scope.localBookTypeTree.push(root);
            }));
            return $q.all(promises);
        };
    }
    return new Tree();

});